import request from '@/utils/request'

const baseUrl = '/system'

/**
 * 分页条件查询用户列表
 * @param query 查询条件
 * @param current 当前页码
 * @param size 每页显示多少数据
 * @returns 
 */
export function getPageList(queryParams: SysUserQuery, pageParams: PageParams) {
  return request({
    url: `${baseUrl}/users`,
    method: 'get',
    params: { ...queryParams, ...pageParams }
  });
}
// checkExist

// 新增用户
export function add(data: SysUserType) {
  return request({
    url: `${baseUrl}/users`,
    method: 'post',
    data: data,
  });
}

// 修改用户
export function update(data: SysUserType) {
  return request({
    url: `${baseUrl}/users`,
    method: 'put',
    data: data,
  });
}

// 删除指定用户id的数据
export function deleteById(id: number) {
  return request({
    url: `${baseUrl}/users/${id}`,
    method: 'delete',
  });
}

/**
 * 校验用户帐号或手机号是否存在
 *  /system/user/exist?username=xxx
 *  /system/user/exist?mobile=xxx
 * @param params 接收{username: xxx} 或者 {mobile: xxxx}
 * @returns
 */
export function checkExist(params: { username: string } | { mobile: string }) {
  return request({
    url: `${baseUrl}/users/exist`,
    method: 'get',
    params //params: params
  })
}

// 重置用户密码
export function updatePassword(data: PwdResetForm) {
  return request({
    url: `${baseUrl}/users/password`,
    method: 'put',
    data
  })
}

export function getRoleList(queryParams: any, pageParams: PageParams) {
  return request({
    url: `/oauth/roles/`,
    method: 'get',
    params: { ...queryParams, ...pageParams },
  });
}

// 获取所有用户
export function getUsernameList() {
  return request({
    url: '/oauth/info/',
    method: 'get',
  });
}